//
//  MatingViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/2/28.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "MatingViewController.h"

#import "PeiDetailsVC.h"
#import "TodoHttpManager.h"
#import "MJExtension.h"
#import "MJEModleView.h"
#import "Model.h"
@interface MatingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *dataArr;
@property(nonatomic,strong)NSMutableArray *qiArr;
@property(nonatomic,strong)NSMutableArray *cheArr;
@property(nonatomic,strong)NSMutableArray *cheIDArr;

@property(nonatomic,strong)NSMutableArray *chuArr;
@property(nonatomic,strong)Model *oneMod;
@property(nonatomic,strong)NSMutableArray *allArr;
@property(nonatomic,strong)NSMutableArray *yiArr;
@property(nonatomic,strong)NSMutableArray *weiArr;




@end

@implementation MatingViewController


-(void)viewWillAppear:(BOOL)animated
{
    //配套房源
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didTDZhuSPeiHouse:) name:TDZhuSPeiHouse object:nil];
//    if (self.chuArr.count ==0 )
//    {
//        [_manager userZhuShouPeiTaoHouse];
//    }
    
}

-(void)didTDZhuSPeiHouse:(NSNotification *)notio
{
    if (notio.object != 0)
    {
        self.oneMod = [Model mj_objectWithKeyValues:notio.object];
        
        [self.dataArr addObject:self.oneMod.data];
        
      //  NSLog(@"-------------==%@",self.oneMod.data);

        for (Data *cheD in self.oneMod.data)
        {
            [self.cheArr addObject:cheD.name];
            [self.cheIDArr addObject:cheD.id];
               NSLog(@"11111-------------==%@",self.cheIDArr);
            for (MainData *dataB in cheD.data)
            {
                [self.chuArr addObject:dataB.wylx];
                [self.allArr addObject:dataB.all_rooms];
                [self.yiArr addObject:dataB.sale_rooms];
                [self.weiArr addObject:dataB.rest_rooms];
            
            }
            
            
        }
        
          [_tableView reloadData];
        
    }
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDZhuSPeiHouse object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
   
    _manager = [TodoHttpManager sharedManager];
 
    if (self.chuArr.count ==0 )
    {
        [_manager userZhuShouPeiTaoHouse];
    }
    
    _cheArr = [[NSMutableArray alloc] init];
    _chuArr = [[NSMutableArray alloc] init];
    _allArr = [[NSMutableArray alloc] init];
    _weiArr = [[NSMutableArray alloc] init];
    _yiArr = [[NSMutableArray alloc] init];
    _cheIDArr = [[NSMutableArray alloc] init];
    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = 40;
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    _tableView.backgroundColor = BgColor;
    [self.view addSubview:_tableView];

}

//楼号数组 数组
-(NSMutableArray *)daArr{
    if (_dataArr) {
        _dataArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArr;
}

//期数数据 数组
//-(NSMutableArray *)qishuArr{
//    if (_qiArr) {
//        _qiArr = [NSMutableArray arrayWithCapacity:0];
//    }
//    return _qiArr;//
//}

//几个表头
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
    //NSLog(@"配套房源的数组长度  %ld",self.dataArr.count);
    
       return _cheArr.count;
}
//
//-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//    
//    if (_cheArr.count != 0) {
//        
//        Model *model = self.cheArr[section];
//        
//        // NSLog(@"0这里是什么呀--------%@",self.daArr[section]);
//        return model.data.count;
//        
//    }
//    
//    return 0;
//    
//}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 2;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentifi = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifi];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifi];
        
    }
    cell.textLabel.textColor = OverColor;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
    cell.textLabel.font = [UIFont systemFontOfSize:14];
  
    cell.textLabel.text = self.chuArr[indexPath.row];
    cell.textLabel.textColor = [UIColor orangeColor];
    cell.detailTextLabel.textColor = [UIColor grayColor];

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    return cell;
}
/*设置标题头的宽度*/
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

/*设置标题头的名称*/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [self.cheArr objectAtIndex:section];
}

/*设置cell 的宽度 */
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 40;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PeiDetailsVC *peiVC = [[PeiDetailsVC alloc] init];
    peiVC.qID = _cheIDArr[indexPath.section];
    peiVC.houseID =self.chuArr[indexPath.row];
    peiVC.allStr = self.allArr[indexPath.row];
    peiVC.yiStr = self.yiArr[indexPath.row];
    peiVC.weiStr = self.weiArr[indexPath.row];
    
  //  NSLog(@"这是第几期======== %@",peiVC.qID );
 // NSLog(@"3333这是车位还是储藏室====%@____%@==== %@",peiVC.allStr,peiVC.yiStr,peiVC.weiStr );
    
    [self.navigationController pushViewController:peiVC animated:NO];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
